package com.jt.tenant.activity;

import android.os.Bundle;
import android.util.Log;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;

import com.jt.tenant.R;
import com.jt.tenant.app.JTApplication;
import com.jt.tenant.widget.Tools;

import java.util.HashMap;

/**
 * Created by Administrator on 2016/4/25.
 */
public class WoPayActivity extends JTActivity {

    private TextView title_name;

    private WebView webView;

    private String GoodsName= "",Expand = "",PayBalance = "";

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_wopay);

        GoodsName = getIntent().getStringExtra("GoodsName");

        Expand = getIntent().getStringExtra("Expand");

        PayBalance = getIntent().getStringExtra("PayBalance");

        title_name = (TextView) findViewById(R.id.tv_title_name);

        webView = (WebView)findViewById(R.id.wv_wopay);

        webView.getSettings().setSupportZoom(true);

        webView.getSettings().setJavaScriptEnabled(true);

        webView.getSettings().setDomStorageEnabled(true);

        webView.setWebViewClient(new WebViewClient() {

            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {

                Log.e("jw","url:"+url);

                try {

                    String protocol = Tools.getUrlScheme(url);

                    if("wopay".equals(protocol)){
                        HashMap<String,String> map = Tools.getUrlParams(url);

                        String result = map.get("payResult");//获取到指定key的参数值，调用本地方法

                        Log.e("payResult==========",result);

                        if(result.equals("1")){

                            if(GSPaymentActivity.wxSuccess != null){

                                GSPaymentActivity.wxSuccess.success("2");

                            }

                            JTApplication.INSTANCE.finishActivity(WoPayActivity.class);

                        }

                    }else {

                        webView.loadUrl(url);

                    }

                }catch (Exception e) {

                    Log.e("jw", "error:"+Log.getStackTraceString(e));

                }

                return true;

            }

        });

        title_name.setText("优路兔");

        Log.e("WO==============","http://101.200.159.207:8080/GSpay/orderPayInfo.jsp?GoodsName="+GoodsName+"&Expand="+Expand+"&PayBalance="+PayBalance);

        webView.loadUrl("http://101.200.159.207:8080/GSpay/orderPayInfo.jsp?GoodsName="+GoodsName+"&Expand="+Expand+"&PayBalance="+PayBalance);

//        try {
//            Thread.sleep(3000);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
//
//        webView.loadUrl("http://192.168.1.134:8080/GSpay/orderPayInfo.jsp?GoodsName=20&Expand=21&PayBalance=22");

    }

}
